<template>
	<view class="container">
		<view class="brand">
			<image :src="userInfo.avatarUrl"></image>
			<view class="username">{{userInfo.nickName}}</view>
		</view>
		<view class="user-form">
			<list-cell line-right padding="30rpx">
				<view class="form-item">
					<view class="label">昵称</view>
					<input type="text" v-model="userInfo.nickName"/>
				</view>
			</list-cell>
			<list-cell line-right padding="30rpx">
				<view class="form-item">
					<view class="label">真实姓名</view>
					<input type="text" v-model="userInfo.realName"/>
				</view>
			</list-cell>
			<list-cell line-right padding="30rpx">
				<view class="form-item">
					<view class="label">手机号码</view>
					<input type="text" v-model="userInfo.phone" />
				</view>
			</list-cell>
			<list-cell line-right padding="30rpx">
				<view class="form-item">
					<view class="label">性别</view>
					<view class="radio" @tap="userInfo.gender =1">
						<image :src="userInfo.gender==2 ? '/static/images/common/gouxuankuang.png' : '/static/images/common/round-black-selected.png'"></image>
						<view>男</view>
					</view>
					<view class="radio" @tap="userInfo.gender =2">
						<image :src="userInfo.gender==1 ? '/static/images/common/gouxuankuang.png' : '/static/images/common/round-black-selected.png'"></image>
						<view>女</view>
					</view>
				</view>
			</list-cell>
			<list-cell line-right padding="30rpx" last>
				<view class="form-item">
					<view class="label">生日</view>
					 <picker class="flex-fill" mode="date" :value="userInfo.birthday" @change="handleBirthdayChange">
						<view>{{ userInfo.birthday }}</view>
					</picker>
				</view>
			</list-cell>
		</view>
		
		<view class="save-btn">
			<button type="info" @click="save">保存</button>
		</view>
		
		<u-top-tips ref="uTips"></u-top-tips>
		
		
	</view>
</template>

<script>
	import listCell from '@/components/list-cell/list-cell.vue'
	import { mapMutations,mapState } from 'vuex'
	
	export default {
		components: {
			listCell,
		},
		data() {
			return {
				telphoneForm: {
					telphone: '',
					verifyCode: ''
				},
				countdown: 0
			}
		},
		computed:{
			...mapState(['isLogin', 'userInfo','isAuth'])
		},
		methods: {
			handleBirthdayChange({target: {value}}) {
				 this.userInfo.birthday = value
			},
			save(){
				let data=this.userInfo;
				let that=this;
				if(this.empty(data.nickName) || this.empty(data.gender) || this.empty(data.realName) || this.empty(data.birthday) || this.empty(data.phone)){
					this.$refs.uTips.show({
									title: '信息不得放空',
									type: 'warning',
									duration: '2300'
								})
				}
				that.$u.api.user.update({
					id:this.userInfo.uid,
					nickname:this.userInfo.nickName,
					realname:this.userInfo.realName,
					mobile:this.userInfo.phone,
					sex:this.userInfo.gender,
					birthday:this.userInfo.birthday
				}).then(res=>{
					this.$refs.uTips.show({
									title: '更新成功',
									type: 'success',
									duration: '2300'
								})
				})
			},
			empty(item){
				return this.$u.test.isEmpty(item)
			}
			
		}
	}
</script>

<style lang="scss" scoped>
.brand {
	background-color: $bg-color-white;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 40rpx 0;
	margin-bottom: 20rpx;
	
	.avatar {
		width: 200rpx;
		height: 200rpx;
		border-radius: 100%;
		margin-bottom: 30rpx;
	}
	
	.username {
		color: $font-size-medium;
		font-weight: bold;
	}
}

.user-form {
	.form-item {
		width: 100%;
		display: flex;
		align-items: center;
		
		.label {
			width: 160rpx;
		}
		
		input {
			flex: 1;
		}
		
		.radio {
			display: flex;
			margin-right: 50rpx;
			image {
				width: 40rpx;
				height: 40rpx;
				margin-right: 20rpx;
			}
		}
	}
}

.save-btn {
	padding: 0 30rpx;
	margin-top: 60rpx;
	
	button {
		width: 100%;
		font-size: $font-size-extra-lg;
	}
}

.telphone-modal {
	.header {
		display: flex;
		align-items: center;
		justify-content: center;
		position: relative;
		font-size: $font-size-extra-lg;
		font-weight: bold;
		margin-bottom: 30rpx;
		
		.close-icon {
			width: 60rpx;
			height: 60rpx;
			position: absolute;
			right: 0;
		}
	}
	
	.tips {
		color: $text-color-grey;
		line-height: 1.2rem;
		margin-bottom: 50rpx;
	}
	
	.telphone-form {
		font-size: $font-size-base;
		
		.telphone-input {
			width: 100%;
			display: flex;
			align-items: center;
			
			.prefix {
				color: $color-primary;
				display: flex;
				align-items: center;
				padding-right: 20rpx;
				position: relative;
				margin-right: 10rpx;
				
				&::after {
					content: " ";
					position: absolute;
					width: 4rpx;
					background-color: $border-color;
				}
			}
			
			input {
				flex: 1;
			}
		}
		
		.verfiycode-input {
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;
			
			.countdown {
				font-size: $font-size-base;
			}
		}
	}
	
	.footer {
		margin-top: 30rpx;
		button {
			font-size: $font-size-lg;
		}
	}
}
</style>
